create_new_arrays Subroutine

public subroutine create_new_arrays(nums, exprs, idx1, idx2, result, new_expr, new_nums, new_exprs)

Creates new arrays after performing an operation.

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: nums(:)

Input: Array of numbers.

character(len=expr_len), intent(in) :: exprs(:)

Input: Array of expressions.

integer, intent(in) :: idx1

Input: Indices of elements to remove.

integer, intent(in) :: idx2

Input: Indices of elements to remove.

real, intent(in) :: result

Input: Result of the operation.

character(len=expr_len), intent(in) :: new_expr

Input: New expression for the result.

real, intent(out), allocatable :: new_nums(:)

Output: New array of numbers with elements removed and result added.

character(len=expr_len), intent(out), allocatable :: new_exprs(:)

Output: New array of expressions with elements removed and new_expr added.


Called by

proc~~create_new_arrays~~CalledByGraph proc~create_new_arrays create_new_arrays proc~solve_24 solve_24 proc~solve_24->proc~create_new_arrays proc~solve_24->proc~solve_24 program~game24_ultra game24_ultra program~game24_ultra->proc~solve_24

Source Code

    subroutine create_new_arrays(nums, exprs, idx1, idx2, result, new_expr, new_nums, new_exprs)
        !! Creates new arrays after performing an operation.
        real, intent(in)                        :: nums(:)
        !! Input: Array of numbers.
        character(len=expr_len), intent(in)     :: exprs(:)
        !! Input: Array of expressions.
        integer, intent(in)                     :: idx1, idx2
        !! Input: Indices of elements to remove.
        real, intent(in)                        :: result
        !! Input: Result of the operation.
        character(len=expr_len), intent(in)     :: new_expr
        !! Input: New expression for the result.
        real, allocatable, intent(out)          :: new_nums(:)
        !! Output: New array of numbers with elements removed and result added.
        character(len=expr_len), allocatable, intent(out) :: new_exprs(:)
        !! Output: New array of expressions with elements removed and new_expr added.
        integer                                 :: i, j, n
        !! Loop counters and size of input arrays.

        n = size(nums)
        allocate (new_nums(n - 1))
        allocate (new_exprs(n - 1))

        j = 0
        do i = 1, n
            if (i /= idx1 .and. i /= idx2) then
                j = j + 1
                new_nums(j) = nums(i)
                new_exprs(j) = exprs(i)
            end if
        end do

        ! Add the result of the operation to the new arrays
        new_nums(n - 1) = result
        new_exprs(n - 1) = new_expr
    end subroutine create_new_arrays